package cn.tedu.csmall.stock.webapi.quartz;

import cn.tedu.csmall.commons.pojo.stock.dto.StockReduceCountDTO;
import cn.tedu.csmall.commons.pojo.stock.entity.Stock;
import cn.tedu.csmall.stock.service.IStockService;
import cn.tedu.csmall.stock.webapi.quartz.config.RabbitMQConfig;
import cn.tedu.csmall.stock.webapi.utils.RedisBloomUtils;
import com.alibaba.nacos.client.naming.utils.RandomUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

@Slf4j
public class QuartzJob implements Job {

//    @Autowired
//    private RabbitTemplate rabbitTemplate;
//
//    static int x=1;
    @Autowired
    private RedisBloomUtils redisBloomUtils;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("-----------------"+ LocalDateTime.now() +"-------------------");
        final String COLOR_BLOOM_KEY = "color_bloom";
        String[] colors = {"red","origin","yellow","green","blue","pink"};
        redisBloomUtils.bfmadd(COLOR_BLOOM_KEY, colors);
        String color = "blue";
        log.info("{}:{}",color, redisBloomUtils.bfexists(COLOR_BLOOM_KEY, color));


//        // 实例化一个Stock对象用于发送
//        Stock stock=new Stock();
//        stock.setId(x++);
//        stock.setCommodityCode("PC100");
//        stock.setReduceCount(1+ RandomUtils.nextInt(20));
//        // 下面开始编写发送操作
//        rabbitTemplate.convertAndSend(
//                RabbitMQConfig.STOCK_EX,
//                RabbitMQConfig.STOCK_ROUT,
//                stock);
//        log.info("发送消息完成:{}",stock);

    }
}
